﻿#ifndef _NET_CLIENT_H_
#define _NET_CLIENT_H_

#include <QObject>
#include <QMap>
#include "JZRpcDataManager.h"

class QTcpSocket;
class QTcpServer;

class JZRpcClient : public QObject {
	Q_OBJECT

public:
	JZRpcClient(QObject * parent = NULL);
	~JZRpcClient();

	bool connectToHost(QString host, int port);
    void connectToHostAsync(QString host, int port);
	void disconnectFromHost();
    bool isConnect();
	
    int packCount();
    bool sendPack(const QJsonObject &pack);
    QJsonObject takePack();
	QJsonObject waitPack(int timeout = 30 * 1000);	        

signals:
    void sigConnect();
	void sigDisConnect();
    void sigError();
	void sigJsonPacket(QJsonObject pack);

private slots:	     
    void onConnected();
    void onDisConnected();
    void onReadyRead();    

private:			
    void dispatchPack();

	QTcpSocket *m_socket;
    int m_net;
    bool m_waitRecv;
    bool m_userDisconnect;

	JZRpcDataManager m_dataManager;
};

#endif
